/*
 * ConversorBase64_frame.java
 *
 * Created on 30 de octubre de 2007, 1:24
 */

package aplicacionbase64;
import java.io.File;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 * 
 * @author Maria Mora
 * @version 1.0
 */
public class ConversorBase64_frame extends javax.swing.JFrame {
    
    private Base64XBRL base;
    private JFileChooser chooser;
    private File ficheroOrigen;
    private File ficheroDestino;
    
    
   
    
    /**
     * Creates new form ConversorBase64_frame
     */
    public ConversorBase64_frame() {
        initComponents();
        
        base=new Base64XBRL();
        chooser=new JFileChooser();
      
        
        
        
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Código Generado  ">//GEN-BEGIN:initComponents
    private void initComponents() {
        buttonGroup1 = new javax.swing.ButtonGroup();
        codificando_frame = new javax.swing.JFrame();
        jProgressBar1 = new javax.swing.JProgressBar();
        jLabel4 = new javax.swing.JLabel();
        decodificando_frame = new javax.swing.JFrame();
        jProgressBar2 = new javax.swing.JProgressBar();
        jLabel5 = new javax.swing.JLabel();
        jtxt_rutaOrigen = new javax.swing.JTextField();
        jtxt_rutaDestino = new javax.swing.JTextField();
        btn_ficheroEntrada = new javax.swing.JButton();
        jbtn_convertir = new javax.swing.JButton();
        jbtn_cancelar = new javax.swing.JButton();
        jbtn_ficheroSalida = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jbtn_codificar = new javax.swing.JRadioButton();
        jbtn_decodificar = new javax.swing.JRadioButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jmn_acercaDe = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        jmn_salir = new javax.swing.JMenuItem();

        codificando_frame.setTitle("Conversi\u00f3n");

        jLabel4.setText("Convirtiendo a BASE 64.....");

        org.jdesktop.layout.GroupLayout codificando_frameLayout = new org.jdesktop.layout.GroupLayout(codificando_frame.getContentPane());
        codificando_frame.getContentPane().setLayout(codificando_frameLayout);
        codificando_frameLayout.setHorizontalGroup(
            codificando_frameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(codificando_frameLayout.createSequentialGroup()
                .add(55, 55, 55)
                .add(codificando_frameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel4)
                    .add(jProgressBar1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 286, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(59, Short.MAX_VALUE))
        );
        codificando_frameLayout.setVerticalGroup(
            codificando_frameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(codificando_frameLayout.createSequentialGroup()
                .add(28, 28, 28)
                .add(jLabel4)
                .add(22, 22, 22)
                .add(jProgressBar1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(39, Short.MAX_VALUE))
        );
        decodificando_frame.setTitle("Conversi\u00f3n");

        jLabel5.setText("Convirtiendo a BASE 64.....");

        org.jdesktop.layout.GroupLayout decodificando_frameLayout = new org.jdesktop.layout.GroupLayout(decodificando_frame.getContentPane());
        decodificando_frame.getContentPane().setLayout(decodificando_frameLayout);
        decodificando_frameLayout.setHorizontalGroup(
            decodificando_frameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(decodificando_frameLayout.createSequentialGroup()
                .add(decodificando_frameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel5)
                    .add(decodificando_frameLayout.createSequentialGroup()
                        .add(55, 55, 55)
                        .add(jProgressBar2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 286, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(59, Short.MAX_VALUE))
        );
        decodificando_frameLayout.setVerticalGroup(
            decodificando_frameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(decodificando_frameLayout.createSequentialGroup()
                .add(jLabel5)
                .add(62, 62, 62)
                .add(jProgressBar2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(71, 71, 71))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Code / Decode Base 64 XBRL ESPA\u00d1A");
        setResizable(false);

        btn_ficheroEntrada.setText("Examinar..");
        btn_ficheroEntrada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_ficheroEntradaActionPerformed(evt);
            }
        });

        jbtn_convertir.setText("Convertir");
        jbtn_convertir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_convertirActionPerformed(evt);
            }
        });

        jbtn_cancelar.setText("Cancelar");
        jbtn_cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_cancelarActionPerformed(evt);
            }
        });

        jbtn_ficheroSalida.setText("Examinar..");
        jbtn_ficheroSalida.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_ficheroSalidaActionPerformed(evt);
            }
        });

        jLabel1.setText("Fichero origen:");

        jLabel2.setText("Fichero destino:");

        jLabel3.setIcon(new javax.swing.ImageIcon("C:\\Documents and Settings\\Maria Mora\\Escritorio\\XBRL\\images.jpg"));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Opci\u00f3n"));
        buttonGroup1.add(jbtn_codificar);
        jbtn_codificar.setSelected(true);
        jbtn_codificar.setText("Codificar");
        jbtn_codificar.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jbtn_codificar.setMargin(new java.awt.Insets(0, 0, 0, 0));

        buttonGroup1.add(jbtn_decodificar);
        jbtn_decodificar.setText("Decodificar");
        jbtn_decodificar.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jbtn_decodificar.setMargin(new java.awt.Insets(0, 0, 0, 0));

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jbtn_codificar)
                    .add(jbtn_decodificar))
                .addContainerGap(24, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jbtn_codificar)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jbtn_decodificar)
                .addContainerGap())
        );

        jMenu1.setText("Ayuda");
        jmn_acercaDe.setText("Acerca de");
        jmn_acercaDe.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmn_acercaDeActionPerformed(evt);
            }
        });

        jMenu1.add(jmn_acercaDe);

        jMenu1.add(jSeparator1);

        jmn_salir.setText("Salir");
        jmn_salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmn_salirActionPerformed(evt);
            }
        });

        jMenu1.add(jmn_salir);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jtxt_rutaDestino, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
                                    .add(jLabel2)
                                    .add(jtxt_rutaOrigen, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jbtn_ficheroSalida)
                                    .add(btn_ficheroEntrada)))
                            .add(jLabel1)))
                    .add(layout.createSequentialGroup()
                        .add(49, 49, 49)
                        .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 50, Short.MAX_VALUE)
                                .add(jbtn_cancelar)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jbtn_convertir))
                            .add(layout.createSequentialGroup()
                                .add(45, 45, 45)
                                .add(jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 160, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .add(5, 5, 5)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jtxt_rutaOrigen, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(btn_ficheroEntrada))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel2)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jtxt_rutaDestino, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jbtn_ficheroSalida))
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(44, 44, 44)
                        .add(jLabel3)
                        .add(23, 23, 23)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jbtn_cancelar)
                            .add(jbtn_convertir)))
                    .add(layout.createSequentialGroup()
                        .add(32, 32, 32)
                        .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-396)/2, (screenSize.height-336)/2, 396, 336);
    }// </editor-fold>//GEN-END:initComponents

    private void jmn_acercaDeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmn_acercaDeActionPerformed

        
        new acercaDe_frame().setVisible(true);
            
        
    
        
    }//GEN-LAST:event_jmn_acercaDeActionPerformed

    private void jmn_salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmn_salirActionPerformed
       
      //Salir de la aplicación
      int opcion= JOptionPane.showConfirmDialog(this, "¿Desea salir de la aplicación?");
      
      //Cerrar programa
      if(opcion== 0){
       this.setVisible(false);  
          
      }
       
       
      
        
    }//GEN-LAST:event_jmn_salirActionPerformed

    private void jbtn_cancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_cancelarActionPerformed
      
        jtxt_rutaDestino.setText("");
        jtxt_rutaOrigen.setText("");
        
        
        
        
    }//GEN-LAST:event_jbtn_cancelarActionPerformed

    private void jbtn_ficheroSalidaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_ficheroSalidaActionPerformed

      //Ruta destino  
       chooser.showSaveDialog(this);
       ficheroDestino=chooser.getSelectedFile();
       jtxt_rutaDestino.setText(ficheroDestino.getName());

        
        
        
    }//GEN-LAST:event_jbtn_ficheroSalidaActionPerformed

    private void btn_ficheroEntradaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_ficheroEntradaActionPerformed

        
        //Fichero de enetrada
       chooser.showOpenDialog(this);
       ficheroOrigen=chooser.getSelectedFile();
       jtxt_rutaOrigen.setText(ficheroOrigen.getName());

    }//GEN-LAST:event_btn_ficheroEntradaActionPerformed

    private void jbtn_convertirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_convertirActionPerformed

     if(ficheroOrigen==null || ficheroDestino==null){
         
      JOptionPane.showMessageDialog(null,"Error durante el proceso de conversión \nEspecifíque fichero origen y fichero destino ","Error",JOptionPane.ERROR_MESSAGE)  ;        
         
     }
     
     else{
        
      try{   
        //CODIFICAR EN BASE 64
        if(jbtn_codificar.isSelected()){ 
           
            codificando_frame.setVisible(true);
            base.codificarFichero(ficheroOrigen,ficheroDestino);
            codificando_frame.setVisible(false);
            JOptionPane.showMessageDialog(null,"La codificación a BASE64 ha concluido con éxito","Información de conversión BASE64",JOptionPane.INFORMATION_MESSAGE)  ;        
      
        }
        
        //DECODIFICAR FICHERO DE BASE 64
        else{
            
            base.decodificarFichero(ficheroOrigen,ficheroDestino);
            JOptionPane.showMessageDialog(null,"La decodificación se ha concluido con éxito","Información de conversión BASE64",JOptionPane.INFORMATION_MESSAGE)  ;              
            
        }
     
     }
     catch(Exception e){
         
      JOptionPane.showMessageDialog(null,"Error durante el proceso de conversión","Error",JOptionPane.ERROR_MESSAGE)  ;        
         
     }
     }
     
    }//GEN-LAST:event_jbtn_convertirActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ConversorBase64_frame().setVisible(true);
            }
        });
    }
    
    // Declaración de varibales -no modificar//GEN-BEGIN:variables
    private javax.swing.JButton btn_ficheroEntrada;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JFrame codificando_frame;
    private javax.swing.JFrame decodificando_frame;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JProgressBar jProgressBar2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JButton jbtn_cancelar;
    private javax.swing.JRadioButton jbtn_codificar;
    private javax.swing.JButton jbtn_convertir;
    private javax.swing.JRadioButton jbtn_decodificar;
    private javax.swing.JButton jbtn_ficheroSalida;
    private javax.swing.JMenuItem jmn_acercaDe;
    private javax.swing.JMenuItem jmn_salir;
    private javax.swing.JTextField jtxt_rutaDestino;
    private javax.swing.JTextField jtxt_rutaOrigen;
    // Fin de declaración de variables//GEN-END:variables
    
}
